package com.wc.acwing.思维.七夕祭;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/2 14:48
 * @description https://www.acwing.com/problem/content/description/107/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    // rowsNum[i] 表示 第i行有多少个
    static int[] rowsNum = new int[N];
    // colsNum[i] 表示 第i列有多少个
    static int[] colsNum = new int[N];
    static long[] c = new long[N];
    static int n, m, t, x, y;

    // 思路： https://www.acwing.com/file_system/file/content/whole/index/content/2399984/
    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        t = sc.nextInt();
        for (int i = 1; i <= t; i++) {
            x = sc.nextInt();
            y = sc.nextInt();
            rowsNum[x]++;
            colsNum[y]++;
        }
        // 都不是整数倍，那肯定排列不出来
        if (t % n > 0 && t % m > 0) {
            out.println("impossible");
        } else if (t % n == 0 && t % m == 0) {
            out.print("both ");
            out.println(get(n, rowsNum) + get(m, colsNum));
        } else if (t % n == 0) {
            out.print("row ");
            out.println(get(n, rowsNum));
        } else {
            out.print("column ");
            out.println(get(m, colsNum));
        }
        out.flush();
    }

    static long get(int n, int[] a) {
        long sum = 0;
        for (int i = 1; i <= n; i++) sum += a[i];
        long avg = sum / n;
        for (int i = 1; i <= n; i++) a[i] -= avg;
        for (int i = 2; i <= n; i++) c[i] = c[i - 1] + a[i];
        Arrays.sort(c, 1, n + 1);
        long mid = c[n / 2 + 1];
        sum = 0;
        for (int i = 1; i <= n; i++) sum += Math.abs(c[i] - mid);
        return sum;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    String nextLine() {
        String line = "";
        try {
            line = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return line;
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    boolean hasNext() {
        while (st == null || !st.hasMoreElements()) {
            try {
                String line = br.readLine();
                if (line == null) return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return true;
    }
}
